<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品列表</title>
    <style>
        li{
            background: skyblue;
        }
    </style>
</head>
<body>
    <h1>商品列表</h1>
    <div id="goodslist">
        <ul></ul>
    </div>
    <script>
        let list = document.querySelector('#goodslist');
        
        // 发送ajax请求
        let xhr = new XMLHttpRequest();
        xhr.open('GET','http://localhost:2003/goodlist',true);
        xhr.send();

        // 接收数据
        xhr.onload = () => {
            let data = JSON.parse(xhr.responseText);
            
            list.innerHTML = data.map(item=>`
                <li idx='${item.id}'>
                    <h3>${item.name}</h3>
                    <p>${item.price}</p>
                </li>
            `).join('');
        }

    </script>
</body>
</html>